import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class tijerator {//{}
	InputStream fis =null   ; 
	OutputStream fos =null;
	OutputStream fos1 =null;
	File in = new File(tijera.txtRuta.getText());
	File out = new File(tijera.txtRutas.getText()+ "1.dat");
	File out1 = new File(tijera.txtRutas.getText()+ "2.dat");

	public void Split() throws IOException{
		 fis = new FileInputStream(in);
		 fos = new FileOutputStream(out);
		 fos1 = new FileOutputStream(out1);
       		 int flen =(int) in.length();
       		 System.out.println(flen);
       		 //double fdivd =flen/2;
       		int fdivd =flen/2;
       		 System.out.println(fdivd);
       		// Double.fdivd.
       		 byte[] buffer = new byte[fdivd];
       		byte[] buffer1 = new byte[fdivd+1];
       		 try {
       			 fis.read(buffer);
				fos.write(buffer, 0,fdivd);
				fos.close();
				fis.read(buffer1);
				fos1.write(buffer1, 0,fdivd);
				fos1.close();
				tijera.txtrInfo.append("\n1.dat y 2.dat escritos");
			} catch (IOException e) {
				System.err.println("Error in datEi");
				
			}
		 
		 
		 Generarbat();
		 
	}

     public void   Generarbat() throws IOException   {
    		OutputStream fos2 =null;
    		File out2 = new File(tijera.txtRutas.getText()+ "instalador.bat");
   		 fos2 = new FileOutputStream(out2);
   		 String kommand = "copy /b 1.dat + 2.dat instalador.exe && cmd /c start instalador.exe";
   		 char k[] =kommand.toCharArray();
   		 byte buffer[] = new        byte[128];
   		 for (int i =0 ; i < k.length;i++){
   		buffer[i]	=    (byte)    k[i];
   			 
   		 }
   		// buffer[1]= (byte) k[1];
   		 System.out.println(buffer);
   		 fos2.write(buffer);
         fos2.close();
         tijera.txtrInfo.append("\nBAT escrito ok");
     }                        

	
}
